added BablImage
authorØyvind Kolås <ok@src.gnome.org>
Tue, 9 Aug 2005 20:24:23 +0000 (20:24 +0000)
committerØyvind Kolås <ok@src.gnome.org>
Tue, 9 Aug 2005 20:24:23 +0000 (20:24 +0000)
ChangeLog
babl/Makefile.am
babl/babl-classes.h
babl/babl-component.c
babl/babl-conversion.c
babl/babl-image.c [new file with mode: 0644]
babl/babl-image.h [new file with mode: 0644]
babl/babl-model.c

index 413251c511a8118135a4e21b8959a1f8e4f54857..ac44b0ee770355b0ef16d3b443b3421ffa16d31b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2005-08-09  Øyvind Kolås  <pippin@gimp.org>
+
+       * babl/Makefile.am
+       * babl/babl-image.c
+       * babl/babl-image.h
+       * babl/babl-classes.h: Added BablImage class.
+
+       * babl/babl-component.c
+       * babl/babl-conversion.c
+       * babl/babl-model.c: Handle BABL_IMAGE in switches.
+
+
 2005-08-09  Øyvind Kolås  <pippin@gimp.org>
 
        * .cvsignore: added INSTALL and README.
index 9337725529017e55a60df2550ae3e69fa0ea422d..23591472a5b753875a7f2ba437f1d33fd87a5ed4 100644 (file)
@@ -8,6 +8,7 @@ c_sources =                             \
        babl-component.c                \
        babl-conversion.c               \
        babl-fish.c                     \
+       babl-image.c                    \
        babl-introspect.c               \
        babl-memory.c                   \
        babl-model.c                    \
@@ -25,6 +26,7 @@ h_sources  =                          \
        babl-ids.h                      \
        babl-internal.h                 \
        babl-introspect.h               \
+       babl-image.h                    \
        babl-fish.h                     \
        babl-memory.h                   \
        babl-model.h                    \
@@ -42,6 +44,7 @@ library_include_HEADERS =             \
        babl-component.h                \
        babl-conversion.h               \
        babl-fish.h                     \
+       babl-image.h                    \
        babl-model.h                    \
        babl-pixel-format.h             \
        babl-sampling.h                 \
index 29f9ed33bb955a5a9c384c516737adcbddc0f04e..7adaa8858187fc0b8f80664edbf28fbd183d32b7 100644 (file)
 #ifndef _BABL_CLASSES_H
 #define _BABL_CLASSES_H
 
-#ifdef BABL_SKETCHPAD
-
-BablClassType
-  BablInstance
-    BablType
-    BablSampling
-    BablComponent
-    BablModel
-    BablPixelFormat
-    BablConversion
-      BablConversionType
-      BablConversionTypePlanar
-      BablConversionModelPlanar
-      BablConversionPixelFormat
-      BablConversionPixelFormatPlanar
-
-maybe it could make sense to split model into the following, where
-the current model would live on in the component model,.
-    BablModelType
-    BablModelSampling
-    BablModelComponent
-
-    BablConversionModelType
-    BablConversionModelSampling
-    BablConversionModelComponent
-#endif
-
 /* Type and PixelFormat */
 typedef void (*BablFuncLinear)    (void  *src,
                                    void  *dst,
@@ -89,6 +62,7 @@ typedef enum {
   BABL_CONVERSION_PIXEL_FORMAT_PLANAR,
 
   BABL_FISH,
+  BABL_IMAGE,
 
   BABL_SKY
 } BablClassType;
@@ -199,9 +173,19 @@ typedef struct
 
 typedef struct
 {
-  BablInstance           instance;
-  union Babl            *source;
-  union Babl            *destination;
+  BablInstance    instance;
+  int             bands;
+  BablComponent **component;
+  void          **data;
+  int            *pitch;
+  int            *stride;
+} BablImage;
+
+typedef struct
+{
+  BablInstance     instance;
+  union Babl      *source;
+  union Babl      *destination;
 } BablFish;
 
 typedef union
@@ -215,6 +199,7 @@ typedef union
   BablPixelFormat pixel_format;
   BablConversion  conversion;
   BablFish        fish;
+  BablImage        image;
 } Babl;
 
 
index ea1e3618d6d3a1ac31869916038aa82e9d517daf..f4180e272ad82160c06cb6b0d4b058b79db84c17 100644 (file)
@@ -95,6 +95,7 @@ babl_component_new (const char *name,
               case BABL_CONVERSION_PIXEL_FORMAT:
               case BABL_CONVERSION_PIXEL_FORMAT_PLANAR:
               case BABL_FISH:
+              case BABL_IMAGE:
                 babl_log ("%s(): %s unexpected",
                           __FUNCTION__, babl_class_name (babl->instance.type));
                 break;
index 8cddb126e1a07d8152dffac6d52374397db28e21..a42cc2df3c0b87696e1a6e30fd97f7c5a66435f1 100644 (file)
@@ -129,9 +129,6 @@ conversion_new (const char                      *name,
   self->time_cost     = time_cost;
   self->loss          = loss;
 
-  assert (BABL_IS_BABL (self->source));
-  assert (BABL_IS_BABL (self->destination));
-
   babl_add_ptr_to_list ((void ***)&(source->type.from), self);
   babl_add_ptr_to_list ((void ***)&(destination->type.to), self);
   
@@ -226,6 +223,9 @@ babl_conversion_new (const char *name,
     
   va_end   (varg);
 
+  assert (source);
+  assert (destination);
+
   self = conversion_new (name, id,
                          source, destination, time_cost, loss, linear, planar, planar_bit);
 
diff --git a/babl/babl-image.c b/babl/babl-image.c
new file mode 100644 (file)
index 0000000..3edc962
--- /dev/null
@@ -0,0 +1,178 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <string.h>
+#include <stdarg.h>
+
+#include "babl-internal.h"
+#include "babl-image.h"
+#include "babl-type.h"
+#include "babl-component.h"
+
+#define BABL_MAX_BANDS 32
+
+static BablImage *db[100]={NULL,};
+
+#if 0
+static int 
+each_babl_image_destroy (Babl *babl,
+                         void *data)
+{
+  babl_free (babl->image.component);
+  babl_free (babl->image.pitch);
+  babl_free (babl->image.stride);
+  babl_free (babl);
+
+  return 0;  /* continue iterating */
+}
+#endif
+
+static BablImage *
+image_new (int             bands,
+           BablComponent **component,
+           void          **data,
+           int            *pitch,
+           int            *stride)
+{
+  BablImage *self;
+  int        band;
+
+  self                = babl_calloc (sizeof (BablImage), 1);
+
+  self->instance.type = BABL_IMAGE;
+  self->instance.id   = 0;
+  self->instance.name = "babl image";
+
+  self->bands         = bands;
+
+  self->component     = babl_malloc (sizeof (BablComponent*) * (bands+1));
+  self->data          = babl_malloc (sizeof (void*)          * (bands+1));
+  self->pitch         = babl_malloc (sizeof (int)            * (bands+1));
+  self->stride        = babl_malloc (sizeof (int)            * (bands+1));
+
+  for (band=0; band < bands; band++)
+    {
+      self->component[band] = component[band];
+      self->data[band]      = data[band];
+      self->pitch[band]     = pitch[band];
+      self->stride[band]    = stride[band];
+    }
+  self->component[band] = NULL;
+  self->data[band]      = NULL;
+  self->pitch[band]     = 0;
+  self->stride[band]    = 0;
+
+  return self;
+}
+
+BablImage *
+babl_image_new (void *first,
+                ...)
+{
+  va_list        varg;
+  BablImage      *self;
+  int            bands     = 0;
+  BablComponent *component [BABL_MAX_BANDS];
+  void          *data      [BABL_MAX_BANDS];
+  int            pitch     [BABL_MAX_BANDS];
+  int            stride    [BABL_MAX_BANDS];
+
+  const char      *arg = first;
+
+  va_start (varg, first);
+
+  while (1)
+    {
+      BablComponent *new_component = NULL;
+      if (!arg)
+        break;
+
+      if (BABL_IS_BABL (arg))
+        {
+          Babl *babl = (Babl*)arg;
+
+          if (babl->instance.type == BABL_COMPONENT)
+            {
+              new_component = (BablComponent *)babl;
+            }
+          else
+            {
+                babl_log ("%s(): %s unexpected",
+                          __FUNCTION__, babl_class_name (babl->instance.type));
+                return NULL;
+            }
+        }
+      else
+        {
+          new_component = babl_component (arg);
+        }
+
+      component [bands] = new_component;
+      data      [bands] = va_arg (varg, void*);
+      pitch     [bands] = va_arg (varg, int);
+      stride    [bands] = va_arg (varg, int);
+      bands++;
+                
+      if (bands>=BABL_MAX_BANDS)
+        {
+          babl_log ("%s(): maximum number of bands (%i) exceeded for BablImage",
+                    __FUNCTION__, BABL_MAX_BANDS);
+        }
+
+      arg = va_arg (varg, char *);
+    }
+    
+  va_end   (varg);
+
+
+  self = image_new (bands, component, data, pitch, stride);
+
+  return self;
+}
+
+void
+babl_image_each (BablEachFunction  each_fun,
+                    void             *user_data)
+{
+  int i;
+  return;
+
+  while (db[i])
+    {
+      if (each_fun ((Babl *) (db[i]), user_data))
+        {
+          return;
+        }
+      else
+        {
+          i++;
+        }
+    }
+}
+
+
+void
+babl_image_destroy (void)
+{
+}
+
+void
+babl_image_init (void)
+{
+}
diff --git a/babl/babl-image.h b/babl/babl-image.h
new file mode 100644 (file)
index 0000000..db4a0c5
--- /dev/null
@@ -0,0 +1,32 @@
+/* babl - dynamically extendable universal pixel conversion library.
+ * Copyright (C) 2005, Øyvind Kolås.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General
+ * Public License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _BABL_IMAGE_H
+#define _BABL_IMAGE_H
+
+#include "babl-classes.h"
+
+void        babl_image_init       (void);
+void        babl_image_introspect (void);
+void        babl_image_each       (BablEachFunction  each_fun,
+                                   void             *user_data);
+void        babl_image_destroy    (void);    
+BablImage * babl_image_new        (void *first_component,
+                                   ...);
+#endif
index c0acc3948e6fdcbb03e4387aa465adfb71b7ee13..e1657aee85fb16dfbf65858e4e6d7160ef8116df 100644 (file)
@@ -119,6 +119,7 @@ babl_model_new (const char *name,
               case BABL_CONVERSION_PIXEL_FORMAT:
               case BABL_CONVERSION_PIXEL_FORMAT_PLANAR:
               case BABL_FISH:
+              case BABL_IMAGE:
                 babl_log ("%s(): %s unexpected",
                           __FUNCTION__, babl_class_name (babl->instance.type));
                 break;